package cn.javase.concurrent._并发编程._06_共享模型之无锁._原子整数._示例;

import java.util.concurrent.atomic.AtomicInteger;

public class AccountSafeCAS implements Account {

    private AtomicInteger balance;

    public AccountSafeCAS(Integer balance) {
        this.balance = new AtomicInteger(balance);
    }

    @Override
    public Integer getBalance() {
        return balance.get();
    }

    @Override
    public void withdraw(Integer amount) {
        balance.addAndGet(-amount);
    }

}
